#include <myheader.h>
#define DOMAIN_SIZE 4
/*Usage:  */
int main(int argc, char *argv[])
{
    //定义字符串数组
    char domain_names[DOMAIN_SIZE][20] = {
        "www.baidu.com",
        "www.alibaba.com",
        "www.jd.com",
        "www.tencent.com"};
    for(int i = 0; i<DOMAIN_SIZE;i++){
    printf("%s\n",domain_names[i]);
    struct addrinfo *res;
    getaddrinfo(domain_names[i],NULL,NULL,&res);
    //会返回一个链表
    //遍历链表
    for(struct addrinfo *p = res; p!=NULL; p = p->ai_next){
        struct sockaddr_in *sock;
        char *str;
        //打印ipv4地址
        if(p->ai_family == AF_INET){
            sock = (struct sockaddr_in*)p->ai_addr;
            struct in_addr addr = sock->sin_addr;
            //将无符号整数的addr转换成百分十进制形式
            str = inet_ntoa(addr);
            printf("%s\n",str);
        }
    }
    freeaddrinfo(res);
    }
    return 0;
}

